<script>
	import Vue from 'vue'
	export default {
		onLaunch: function() {
			console.log('App Launch')
			//项目启动时 优先加载本地缓存
			this.initBaseData();
			this.registerUser();
			var that = this;
			 uni.getSystemInfo({
				success: function(e) {
					// #ifndef MP
					Vue.prototype.StatusBar = e.statusBarHeight;
					if (e.platform == 'android') {
						Vue.prototype.CustomBar = e.statusBarHeight + 50;
					} else {
						Vue.prototype.CustomBar = e.statusBarHeight + 45;
					};
					// #endif
					// #ifdef MP-WEIXIN
					Vue.prototype.StatusBar = e.statusBarHeight;
					let custom = wx.getMenuButtonBoundingClientRect();
					Vue.prototype.Custom = custom;
					Vue.prototype.CustomBar = custom.bottom + custom.top - e.statusBarHeight;
					that.globalData.barHeight = Vue.prototype.CustomBar
					// #endif       
					// #ifdef MP-ALIPAY
					Vue.prototype.StatusBar = e.statusBarHeight;
					Vue.prototype.CustomBar = e.statusBarHeight + e.titleBarHeight;
					// #endif
				}
			})
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		},
		globalData:{
			uid:0,
			isFirstLogin:false,
			showVideoCourse:false,
			author:'微信:Lanyu4567',
			notice:'有问题请及时联系作者进行反馈',
			x:0,
			y:0,
			width:10,
			height:10,
			prizeContent:'赞赏下作者 下载提速',
			prizePath:'pages/apps/largess/detail?id=fmpt2URXZgCgPc1CLmE7uw%3D%3D',
			banner:[{
				imgUrl:'http://parse-video-server.oss-cn-hangzhou.aliyuncs.com/oDXAOay1MYfbl7h.png',
				type:0
			}],
			videoAdTimes:3,
			batchAnalyse:2,
			shareImg:'http://parse-video-server.oss-cn-hangzhou.aliyuncs.com/share/mangguogongju.png',
			shareTitle:'抖音、快手、皮皮虾短视频一键去水印,去水印还能这么简单',
			prizeImg:'http://parse-video-server.oss-cn-hangzhou.aliyuncs.com/share/prizeImg.png',
			prizeType:0,
			nickName:'用户',
			headUrl:'https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=2401491928,907118315&fm=27&gp=0.jpg',
			watchTimes:1,
			autoDownload:false,
			adTip:'还没有看完广告 一天仅需看一次广告 24小时免除广告',
			sharePic:'http://parse-video-server.oss-cn-hangzhou.aliyuncs.com/share.png',
			playAddr:null,
			cover:null,
			shareBtn:'分享给好友',
			indexAd:'',
			videoAd:'',
			videoAdReward:'',
			videoAdCard:'',
			toolAd:'',
			myAd:'',
			videoAdAfter:'',
			parseAd:'',
			parseAdCard:'',
			batchAd:'',
			fontAd:'',
			md5Ad:'',
			picToTextAd:'',
			barHeight:60,
			analyseUrl:'请输入视频链接',
			title:'',
			token:'',
			fileType:0,
			access:'yytkjfgzmnklfgyy',
			pics:[],
			skipList:[],
			course:0,
			unPlat:[],
			globalColor:'bg-blue',
			parseSkip:0,
			parseTitle:'去水印工具'
		},
		methods:{
			initBaseData:function() {
				var that = this;
				var autoDownload = uni.getStorageSync('autoDownload');
				if(null != autoDownload && typeof(autoDownload) != 'undefined') {
					this.$options.globalData.autoDownload = autoDownload;
				}
				var basedata = uni.getStorageSync('basedata');
				if(null != basedata && typeof(basedata) != "undefined" && '' != basedata) {
					console.log("加载本地缓存中的基础数据")
					if(null != basedata.author) {
						this.$options.globalData.author = basedata.author;
					}
					if(null != basedata.videoAd) {
						this.$options.globalData.prizeImg = basedata.videoAd;
					}
					this.$options.globalData.prizeContent = basedata.link;
					this.$options.globalData.showVideoCourse = basedata.course;
					this.$options.globalData.notice = basedata.content,
					this.$options.globalData.prizePath = basedata.prizePath;
					this.$options.globalData.banner = basedata.bannerList
					this.$options.globalData.batchAnalyse = basedata.batchAnalyse;
					this.$options.globalData.shareImg = basedata.adPath;
				}else {
					//新用户进入  默认加载自己的所有信息
				}
			},
			registerUser() {
				var that = this;
				const cacheToken = uni.getStorageSync('token');
				if (cacheToken) {
					console.log(cacheToken)
					that.$options.globalData.token = cacheToken;
				}
				wx.login({
				  success (res) {
					const code = res.code; 					
					uni.request({
						url:  that.$reqUrl+'/video/registryUser',
						data: {
							code: code,
							programType:that.$source
						},
						success: (res) => {
							if(res.data.code == '0001') {
								console.log(res.data.data)
								uni.setStorageSync('userId', res.data.data.userId);
								that.$options.globalData.uid = res.data.data.userId;
								that.$options.globalData.token = res.data.data.token;
								uni.setStorageSync('token',res.data.data.token)
								/* if(res.data.data.isFirstLogin) {
									uni.showModal({
										content:'检测到您是首次登录，是否需要学习如何去水印？',
										confirmText:'立即学习',
										success(res) {
											if(res.confirm) {
												uni.navigateTo({
													url:'../parse/parse?conId=3'
												})
											}
										}
									})
								} */
							}else {
								uni.showModal({
									content:'注册用户信息异常'
								})
							}			
						},
						fail(res) {
							uni.showModal({
								content:'服务器维护中 请稍后重试 有问题请联系作者'
							})
						}
					});
				  }
				})
			}
		}
	}
</script>

<style>
	@import "colorui/main.css";
	@import "colorui/icon.css";
	
</style>
